﻿#include "../lv_Agriculture.h"

static void lv_WIFIList_Content(lv_obj_t* parent);
lv_obj_t* lv_WIFIList_AddWIFI(lv_obj_t* parent,const char * WIFI_Name);
void lv_WIFIListExit_Callback(lv_event_t* e);
void lv_WIFIListExit_Btn(lv_obj_t* parent);


lv_obj_t* lv_WIFIList_Srceen;
lv_group_t * wifi_list_group;

void lv_WIFIList_Page(void)
{
    lv_WIFIList_Srceen = lv_obj_create(NULL);
    lv_obj_add_style(lv_WIFIList_Srceen, &lv_Clean_Style, LV_STATE_DEFAULT);
    lv_obj_clear_flag(lv_WIFIList_Srceen, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_size(lv_WIFIList_Srceen, 320, 240);

    lv_Top_StateBar(lv_WIFIList_Srceen);  //顶部状态栏
    lv_WIFIList_Content(lv_WIFIList_Srceen);
    lv_WIFIListExit_Btn(lv_WIFIList_Srceen);
}

static void lv_WIFIList_Content(lv_obj_t* parent)
{
    lv_obj_t* WIFIList_Content = lv_obj_create(parent);
    lv_obj_add_style(WIFIList_Content, &lv_Clean_Style, LV_STATE_DEFAULT);
    lv_obj_set_align(WIFIList_Content, LV_ALIGN_BOTTOM_MID);
    lv_obj_set_size(WIFIList_Content, lv_pct(100), lv_pct(85));
    lv_obj_set_flex_flow(WIFIList_Content, LV_FLEX_FLOW_COLUMN);
    lv_obj_set_flex_align(WIFIList_Content, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);


    wifi_list_group = lv_group_create();
    lv_indev_set_group(indev_keypad, wifi_list_group);


    lv_obj_t* list = lv_list_create(WIFIList_Content);
    lv_obj_set_size(list, lv_pct(100), lv_pct(100));
    
    lv_WIFIList_AddWIFI(list,"TestWIFI");
    lv_WIFIList_AddWIFI(list, "TestWIFI2");
}


lv_obj_t* lv_WIFIList_AddWIFI(lv_obj_t* parent,const char * WIFI_Name)
{
    lv_obj_t* WIFI_Item = lv_list_add_btn(parent, LV_SYMBOL_WIFI, WIFI_Name);
    lv_obj_add_event_cb(WIFI_Item, WIFI_Callback, LV_EVENT_PRESSED, lv_list_get_btn_text(parent, WIFI_Item));
    lv_group_add_obj(wifi_list_group,WIFI_Item);
    return WIFI_Item;
}

void lv_WIFIListExit_Btn(lv_obj_t* parent)
{
    lv_obj_t* Exit_Btn = lv_btn_create(parent);
    lv_obj_t* Exit_Label = lv_label_create(Exit_Btn);
    lv_label_set_text(Exit_Label, LV_SYMBOL_LEFT);
    lv_obj_set_align(Exit_Btn, LV_ALIGN_BOTTOM_LEFT);
   
    lv_obj_add_event_cb(Exit_Btn, lv_WIFIListExit_Callback, LV_EVENT_ALL, NULL);
    lv_group_add_obj(wifi_list_group,Exit_Btn);
}

void lv_WIFIListExit_Callback(lv_event_t* e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t* target = lv_event_get_target(e);
    if (event_code == LV_EVENT_CLICKED) {
        lv_Setting_Page();
        lv_scr_load_anim(lv_Setting_Screen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, false);
    }
}
